<?php

/**
 * Désinstallation du plugin sponsorpress
 * @global wpdb $wpdb
 */
function wp_sponsorpress_uninstall() {

    global $wpdb;
    /*$table_projets_name = $wpdb->prefix.'wpspo_defis';
    $table_promesse_name = $wpdb->prefix.'wpspo_promesse';
    $table_users_name = $wpdb->prefix.'wpspo_users';
    if($wpdb->get_var("SHOW TABLES LIKE '$table_projets_name'") == $table_projets_name)
    {
        //création de la table
        $sql = "DROP TABLE `$table_projets_name`";
        $wpdb->query($sql);
        $sql = "DROP TABLE `$table_promesse_name`";
        $wpdb->query($sql);
        $sql = "DROP TABLE `$table_users_name`";
        $wpdb->query($sql);
    }
    $listeProjets = get_posts( array(
        'post_type'   => array('projet', 'defi'),
        'post_status' => array('publish', 'pending', 'auto-draft', 'inherit', 'trash'),
        ) );

    if ( count( $listeProjets ) > 0 ) {

        foreach ( $listeProjets as $listeProjet ) {
               $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s ", $listeProjet->ID, 'wpspo_choixprojets' );
               wp_delete_post($listeProjet->ID);
        }
    }*/

    wp_delete_post(get_option('wp_sponsorpress_organiser'));
    wp_delete_post(get_option('wp_sponsorpress_projets'));
    wp_delete_post(get_option('wp_sponsorpress_defis'));
    wp_delete_post(get_option('wp_sponsorpress_gestion'));
    wp_delete_post(get_option('wp_sponsorpress_archives'));
    wp_delete_post(get_option('wp_sponsorpress_participants'));
    
    /*delete_option('wp_sponsorpress_version');
    delete_option('wpspo_emails_settings');
    delete_option('wpspo_currency');
    delete_option('wpspo_currency_pos');
    delete_option('wpspo_plugin_settings');*/
    delete_option('wp_sponsorpress_projets');
    delete_option('wp_sponsorpress_defis');
    delete_option('wp_sponsorpress_gestion');
    delete_option('wp_sponsorpress_organiser');
    delete_option('wp_sponsorpress_archives');
    delete_option('wp_sponsorpress_participants');
    
    //delete_option($this->adminOptionsName);
    //remove_role( 'participant' );
}
register_deactivation_hook(__FILE__, 'wp_sponsorpress_uninstall');

/* Si on désactive le plugin alors on supprime le cron : */
/*
register_deactivation_hook( __FILE__, 'wpspo_supprimer_mon_cron' );
function wpspo_supprimer_mon_cron(){
  wp_clear_scheduled_hook( 'wpspo_hook_mails' );
}
*/